package com.liuwei.classy.dao;


import com.liuwei.classy.model.Pagination;
import com.liuwei.classy.model.Paper;
import com.liuwei.classy.model.Shiti;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * Created by qingshengzheng on 17/10/12.
 */
@Mapper
@CacheConfig(cacheNames = "paper")
public interface PaperMapper {

    @Cacheable(key="'PAPER_DETAIL:'+#p0+''")
    @Select("SELECT * FROM paper WHERE id = #{id}")
    public Paper getPaper(@Param("id") String id);

    @Cacheable(key="'SHITI_DETAIL:'+#p0+''")
    @Select("SELECT * FROM answer WHERE id = #{id}")
    public Shiti getShitiById(@Param("id") String id);

    public void addPaperRel(Long uid, String pid);

    @Select("SELECT pid FROM paper_collect where uid=#{uid}  ")
    public List<String > getCollectPapers(@Param("uid")Long uid);

    @Select("SELECT id from answer where id=#{id}")
    public List<String> aidsOfPaper(String pid);


    public List<Shiti> getCollectShitis(Long uid, Integer pageno, Integer pagesize);

    public List<Paper> historyPapers(Long uid, Integer pageno, Integer pagesize);

    public List<Shiti> shitisOfPaper(String pid);

    public List<Paper> filterPaper(Paper paper, Integer pageno, Integer pagesize);


    @Insert("INSERT INTO paper_collect(uid,pid,createtime) VALUES(#{uid},#{pid},#{createtime})")
    public int collectPaper(@Param("uid") Long uid, @Param("pid") String pid,@Param("createtime")Long createtime);

    public int collectShiti(Long uid,String aid);
}
